load("//bazel:flags.bzl", "bool_flag")
load("//bazel:skia_rules.bzl", "exports_files_legacy", "skia_cc_library", "skia_filegroup", "split_srcs_and_hdrs")

package(
    default_applicable_licenses = ["//:license"],
)

licenses(["notice"])

exports_files_legacy()

VK_FILES = [
    "GrVkBackendSemaphore.cpp",
    "GrVkBackendSurface.cpp",
    "GrVkBackendSurfacePriv.h",
    "GrVkBuffer.cpp",
    "GrVkBuffer.h",
    "GrVkCaps.cpp",
    "GrVkCaps.h",
    "GrVkCommandBuffer.cpp",
    "GrVkCommandBuffer.h",
    "GrVkCommandPool.cpp",
    "GrVkCommandPool.h",
    "GrVkContextThreadSafeProxy.cpp",
    "GrVkContextThreadSafeProxy.h",
    "GrVkDescriptorPool.cpp",
    "GrVkDescriptorPool.h",
    "GrVkDescriptorSet.cpp",
    "GrVkDescriptorSet.h",
    "GrVkDescriptorSetManager.cpp",
    "GrVkDescriptorSetManager.h",
    "GrVkDirectContext.cpp",
    "GrVkFramebuffer.cpp",
    "GrVkFramebuffer.h",
    "GrVkGpu.cpp",
    "GrVkGpu.h",
    "GrVkImage.cpp",
    "GrVkImage.h",
    "GrVkImageLayout.h",
    "GrVkImageView.cpp",
    "GrVkImageView.h",
    "GrVkManagedResource.h",
    "GrVkMSAALoadManager.cpp",
    "GrVkMSAALoadManager.h",
    "GrVkOpsRenderPass.cpp",
    "GrVkOpsRenderPass.h",
    "GrVkPipeline.cpp",
    "GrVkPipeline.h",
    "GrVkPipelineState.cpp",
    "GrVkPipelineState.h",
    "GrVkPipelineStateBuilder.cpp",
    "GrVkPipelineStateBuilder.h",
    "GrVkPipelineStateCache.cpp",
    "GrVkPipelineStateDataManager.cpp",
    "GrVkPipelineStateDataManager.h",
    "GrVkRenderPass.cpp",
    "GrVkRenderPass.h",
    "GrVkRenderTarget.cpp",
    "GrVkRenderTarget.h",
    "GrVkResourceProvider.cpp",
    "GrVkResourceProvider.h",
    "GrVkSampler.cpp",
    "GrVkSampler.h",
    "GrVkSamplerYcbcrConversion.cpp",
    "GrVkSamplerYcbcrConversion.h",
    "GrVkSemaphore.cpp",
    "GrVkSemaphore.h",
    "GrVkTexture.cpp",
    "GrVkTexture.h",
    "GrVkTextureRenderTarget.cpp",
    "GrVkTextureRenderTarget.h",
    "GrVkTypesPriv.cpp",
    "GrVkTypesPriv.h",
    "GrVkUniformHandler.cpp",
    "GrVkUniformHandler.h",
    "GrVkUtil.cpp",
    "GrVkUtil.h",
    "GrVkVaryingHandler.cpp",
    "GrVkVaryingHandler.h",
]

split_srcs_and_hdrs(
    name = "vk",
    files = VK_FILES,
)

bool_flag(
    name = "enable_secondary_draw_context",
    default = False,
)

skia_filegroup(
    name = "vk_chromium_srcs",
    srcs = ["GrVkSecondaryCBDrawContext.cpp"],
)

skia_filegroup(
    name = "android_srcs",
    srcs = ["AHardwareBufferVk.cpp"],
)

skia_filegroup(
    name = "srcs",
    srcs = [
        ":android_srcs",
        ":vk_srcs",
    ] + select({
        ":enable_secondary_draw_context_true": [":vk_chromium_srcs"],
        "//conditions:default": [],
    }),
    visibility = ["//src/gpu/ganesh:__pkg__"],
)

skia_filegroup(
    name = "private_hdrs",
    srcs = [":vk_hdrs"],
    visibility = ["//src/gpu/ganesh:__pkg__"],
)

skia_cc_library(
    name = "ganesh_vulkan",
    srcs = [
        ":vk_hdrs",
        ":vk_srcs",
        "//include/private/gpu/vk:private_hdrs",
    ],
    hdrs = [
        "//include/gpu:ganesh_hdrs",
        "//include/gpu/ganesh:ganesh_hdrs",
        "//include/gpu/ganesh/vk:public_hdrs",
        "//include/gpu/vk:public_hdrs",
    ],
    features = ["layering_check"],
    local_defines = [
        "SK_USE_VMA",  # TODO(kjlubick, egdaniel) Turn this off by default and remove.
    ],
    visibility = ["//:__pkg__"],
    deps = [
        "//:core",
        "//src/base",
        "//src/core:core_priv",
        "//src/gpu",
        "//src/gpu/ganesh",
        "//src/gpu/vk",
        "//src/gpu/vk/vulkanmemoryallocator:vulkanmemoryallocator_priv",
        "@vulkan_headers",
    ],
)

# TODO(lovisolo, kjlubick): Do this with a macro.
skia_cc_library(
    name = "ganesh_vulkan_TEST_UTIL",
    testonly = True,
    srcs = [
        ":vk_hdrs",
        ":vk_srcs",
        "//include/private/gpu/vk:private_hdrs",
        "//src/gpu/vk:private_hdrs",
    ],
    hdrs = [
        "//include/gpu:ganesh_hdrs",
        "//include/gpu/ganesh:ganesh_hdrs",
        "//include/gpu/ganesh/vk:public_hdrs",
        "//include/gpu/vk:public_hdrs",
    ],
    defines = [
        "SK_GANESH",
        "SK_VULKAN",
    ],
    features = ["layering_check"],
    local_defines = [
        "GR_TEST_UTILS",
        "SK_USE_EXTERNAL_VULKAN_HEADERS",
    ],
    visibility = ["//tools:__subpackages__"],
    deps = [
        "//:core",
        "//src/base",
        "//src/core:core_priv",
        "//src/gpu",
        "//src/gpu/ganesh:ganesh_TEST_UTIL",
        "//src/gpu/vk",
        "//src/gpu/vk/vulkanmemoryallocator:vulkanmemoryallocator_priv",
        "@vulkan_headers",
    ],
)
